package com.mask.im.business.controller.friend;

import com.mask.im.business.annotation.AesCrypto;
import com.mask.im.business.annotation.OptLog;
import com.mask.im.business.model.dto.FriendGroupDTO;
import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.model.entity.chat.IMFriendGroupsDO;
import com.mask.im.business.model.vo.UpdateFriendGroupVO;
import com.mask.im.business.service.IMFriendGroupsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.mask.im.business.common.constant.OptTypeConstant.SAVE;

/**
 * 好友分组管理
 *
 * @author jian
 */
@Api(tags = "好友分组模块")
@RestController
public class IMFriendGroupsController {

    @Resource
    private IMFriendGroupsService friendGroupsService;

    @ApiOperation("获取当前用户的所有分组")
    @GetMapping("/users/get/currentAllGroup")
    public RestResponse<List<IMFriendGroupsDO>> getCurrentAllGroup() {
        return friendGroupsService.getCurrentAllGroup();
    }

    @ApiOperation("获取当前用户的分组及好友所在分组")
    @GetMapping("/users/getFriendGroup")
    public RestResponse<List<FriendGroupDTO>> getFriendGroup() {
        return friendGroupsService.getFriendGroup();
    }


    @ApiOperation("根据分组Id获取分组")
    @GetMapping("/users/getByIdGroup")
    public RestResponse<IMFriendGroupsDO> getByIdGroup(@RequestParam("groupId") Integer groupId) {
        return friendGroupsService.getByIdGroup(groupId);
    }

    @OptLog(optType = SAVE)
    @ApiOperation("添加分组")
    @PostMapping("/users/addFriendGroup")
    @AesCrypto
    public RestResponse<String> addFriendGroup(@RequestBody IMFriendGroupsDO imFriendGroupsDO) {
        return friendGroupsService.addFriendGroup(imFriendGroupsDO);
    }


    @ApiOperation("删除分组")
    @DeleteMapping("/users/deleteFriendGroup")
    public RestResponse<String> deleteFriendGroup(@RequestParam("groupId") Integer groupId) {
        return friendGroupsService.deleteFriendGroup(groupId);
    }

    @ApiOperation("更改分组")
    @PutMapping("/users/updateFriendGroup")
    public RestResponse<String> updateFriendGroup(@RequestParam("groupId") Integer groupId,
                                                  @RequestParam("groupName") String groupName,
                                                  @RequestParam("sort") Integer sort) {
        return friendGroupsService.updateFriendGroup(groupId, groupName, sort);
    }

    @ApiOperation("获取用户所属组别")
    @GetMapping("/users/getBelongsGroup")
    public RestResponse<IMFriendGroupsDO> getBelongsGroup(@RequestParam("friendId") Integer friendId) {
        return friendGroupsService.getBelongsGroup(friendId);
    }

    @ApiOperation("将好友移动到另一个组别")
    @PostMapping("/users/moveFriendGroup")
    @AesCrypto
    public RestResponse<IMFriendGroupsDO> moveFriendGroup(@RequestBody UpdateFriendGroupVO updateFriendGroupVO) {
        return friendGroupsService.moveFriendGroup(updateFriendGroupVO);
    }
}

